{include file="public/header"/}
</head>
<body>
<div class="layui-form" id="LAY-component-layer-list">
    <div class="layui-fluid d83">
        <div class="layui-col-sm12">
            <div class="layui-card pcf30">
            <div class="layui-form-item">
                <label class="layui-form-label"><b class="pcfts">*</b> 模型名称</label>
                <div class="layui-input-inline pcfcms_layui-input-inline">
                 <input type="text" name="ntitle" value="" lay-verify="required" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><b class="pcfts">*</b> 模型标识</label>
                <div class="layui-input-inline pcfcms_layui-input-inline">
                <input type="text" name="nid" value="" id="nid" lay-verify="required|check_nid" class="layui-input" onkeyup="this.value=this.value.replace(/[^a-z0-9]/g,'');" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^a-z0-9]/g,''));">
                <div class="layui-input-block2" style="padding:10px 0;">
                    与文档的模板相关连，建议由小写字母、数字组成，因为部份Unix系统无法识别中文文件。<br/>
                    列表模板是：lists_模型标识.html<br/>
                    文档模板是：view_模型标识.html
                </div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">选择图标</label>
                <div class="layui-input-block">
                   <input type="text" name="icon" id="iconHhysFa" value="" class="layui-input" lay-verify="iconHhysFa">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">标题重复</label>
                <div class="layui-input-block">
                <input type="checkbox" lay-filter="is_repeat_title" lay-skin="switch" lay-text="是|否" checked>
                <input type="hidden" name="is_repeat_title" value="1" />
                </div>
                是否允许内容标题的重复
            </div>
        </div>
    </div>
    <div class="pcfclear"></div>
    </div>
    <div class="submit-info text-center">
        <button class="layui-btn" lay-submit lay-filter="formSubmit">确认提交</button>
        <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
    </div>
</div>
{include file="public/footer"/}
<script>
  layui.use(['layer', 'form', 'iconHhysFa'], function () {
    var $ = layui.$,
        layer = layui.layer,
        form = layui.form,
        layer = layui.layer,
        iconHhysFa = layui.iconHhysFa;

        //图标选择器
        iconHhysFa.render({
            // 选择器，推荐使用input
            elem: '#iconHhysFa',
            // 数据类型：fontClass/awesome，推荐使用fontClass
            type: 'fontClass',
            // 是否开启搜索：true/false，默认true
            search: true,
            // 是否开启分页：true/false，默认true
            page: true,
            // 每页显示数量，默认12
            limit: 12,
            url: '',
            // 点击回调
            click: function(data) {
                //console.log(data);
            },
            // 渲染成功后的回调
            success: function(d) {
                //console.log(d);
            }
        });

        // 监听开关
        form.on('switch', function(data){
          var elemId = data.elem.attributes['lay-filter']['nodeValue'];
          if (data.elem.checked) {
            this.value = 1;
          } else {
            this.value = 0;
          }
          $("input[name='"+elemId+"']").val(this.value);
        });
        
        //监听提交
        form.on('submit(formSubmit)', function(data){
            layer.msg('正在处理请勿刷新页面', {icon: 16,shade: 0.01,time:3600000});
            $.ajax({
                type : 'post',
                url : '{:url("/type/add")}',
                data : data.field,
                dataType : 'json',
                success : function(res){
                    layer.closeAll('loading');
                    if(res.status){
                        layer.msg(res.msg, {icon: 1, time: 1000}, function(){
                            parent.window.location.href = res.url;
                            //$.get("{:url('/index/clearCache')}");
                        });
                    }else{
                        layer.msg(res.msg, {icon: 2, time: 1000});
                    }
                },
                error: function(e){
                    layer.closeAll('loading');
                    layer.msg("未知错误，操作中断！", {icon: 2, time: 1000});
                }
            });
            return false;
        })
    });
</script>